﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Windows.Controls;

namespace WpfConsole
{
    interface IBookTarget
    {
        DateTime LastChange { get; }
        void SendCommand(string command);
    }

    class CommandBooker
    {
        private IBookTarget _bookTarget;

        private ObservableCollection<ComboBoxItem> _commands = new ObservableCollection<ComboBoxItem>();
        public ObservableCollection<ComboBoxItem> Commands { get { return _commands; } }

        public CommandBooker(IBookTarget target)
        {
            _bookTarget = target;
        }

        internal DateTime LastChange
        {
            get
            {
                return _bookTarget.LastChange;
            }
        }

        // must be called from UI thread.
        internal void FireFirstCommand()
        {
            ComboBoxItem command = _commands[0];
            _commands.RemoveAt(0);
            _bookTarget.SendCommand((string)command.Content);
        }
    }
}
